package com.cloud.phone.utils;

import android.content.Context;
import android.media.MediaScannerConnection;
import android.net.Uri;
import android.util.Log;

import java.io.File;

public class MediaRefreshHelper {
    Context context;

    public MediaRefreshHelper(Context context) {
        this.context = context;
    }

    public void scanFolder(File folder) {
        if (folder != null && folder.isDirectory()) {
            File[] files = folder.listFiles();
            if (files != null) {
                for (File file : files) {
                    if (file.isFile()) {
                        scanFile(file);
                    } else if (file.isDirectory()) {
                        scanFolder(file);
                    }
                }
            }
        }
    }

    public void scanFile(File file) {
        MediaScannerConnection.scanFile(context, new String[]{file.getAbsolutePath()}, null, new MediaScannerConnection.OnScanCompletedListener() {
            public void onScanCompleted(String path, Uri uri) {
                Log.i("MediaScanner", "Scanned " + path + ":");
                Log.i("MediaScanner", "-> uri=" + uri);
            }
        });
    }
}
